package com.example.myapplication.ui.register;

import android.text.Editable;
import android.text.TextWatcher;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

/**
 * 注册 中心的 ViewModel
 * ViewModel 贯穿 整个activity 的中心
 */
public class RegisterViewModel extends ViewModel {

    private MutableLiveData<String> name;
    private MutableLiveData<String> password;
    private MutableLiveData<String> two_password;


    public MutableLiveData<String> getName() {
        if(name==null){
            name=new MutableLiveData<>();
            name.setValue("");
        }
        return name;
    }

    public void setName(MutableLiveData<String> name) {
        this.name = name;
    }

    public MutableLiveData<String> getPassword() {
        if(password==null){
            password=new MutableLiveData<>();
            password.setValue("");
        }
        return password;
    }

    public void setPassword(MutableLiveData<String> password) {
        this.password = password;
    }

    public MutableLiveData<String> getTwo_password() {
        if(two_password==null){
            two_password=new MutableLiveData<>();
            two_password.setValue("");
        }
        return two_password;
    }

    public void setTwo_password(MutableLiveData<String> two_password) {
        this.two_password = two_password;
    }

    public  TextWatcher nameInput =new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            name.setValue(String.valueOf(s));
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };

    public  TextWatcher passwordInput =new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            password.setValue(String.valueOf(s));
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };

    public  TextWatcher twoInput =new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            two_password.setValue(String.valueOf(s));
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };

}